<template>
  <el-card>
    <template #header>
      <div class="card-header h-box justify-between">
        <span>系统指令</span>
      </div>
    </template>
    <div class="h-box"
         style="height: 157px;    align-items: flex-start;">
      <el-select v-model="selectData"  style="width: 150px" placeholder="选择指令">
        <el-option value="2" label="程序重启"></el-option>
        <el-option value="4" label="系统重启"></el-option>
        <el-option value="1" label="虚拟服务重启"></el-option>
        <el-option value="3" label="恢复出厂"></el-option>
        <el-option value="5" label="清空日志"></el-option>
      </el-select>
      <base-button :disabled="!selectData" @click="setCfg" class="mg-l-sm" type="start_save_icon"></base-button>
    </div>
  </el-card>
</template>

<script setup lang="ts">
import SelectIfaceInput from "@/components/SelectIfaceInput/index.vue";
import BaseButton from "@/components/BaseButton/index.vue";
import { ElMessage, ElMessageBox } from "element-plus";
import { ref } from "vue";
import { cfgClearlog, cfgReboot, cfgReset, cfgRestart, srvcfgRestart } from "@/api/modules/system/params";

const selectData = ref("");

async function setCfg() {
  if(!selectData.value){

    return;
  }
  if (selectData.value == 1) {
    await ElMessageBox.confirm("您确定虚拟服务重启吗?", "温馨提示", {
      confirmButtonText: "确定",
      cancelButtonText: "取消",
      type: "warning"
    });
    await srvcfgRestart();
  }
  if (selectData.value == 2) {
    await ElMessageBox.confirm("您确定程序重启吗?", "温馨提示", {
      confirmButtonText: "确定",
      cancelButtonText: "取消",
      type: "warning"
    });
    await cfgRestart();
  }
  if (selectData.value == 3) {
    await ElMessageBox.confirm("您确定恢复出厂吗?", "温馨提示", {
      confirmButtonText: "确定",
      cancelButtonText: "取消",
      type: "warning"
    });
    await cfgReset();
  }
  if (selectData.value == 4) {
    await ElMessageBox.confirm("您确定系统重启吗?", "温馨提示", {
      confirmButtonText: "确定",
      cancelButtonText: "取消",
      type: "warning"
    });
    await cfgReboot();
  }
  if (selectData.value == 5) {
    await ElMessageBox.confirm("您确定清空日志吗?", "温馨提示", {
      confirmButtonText: "确定",
      cancelButtonText: "取消",
      type: "warning"
    });
    await cfgClearlog();
  }
  ElMessage.success("更新成功");
}
</script>

<style scoped></style>
